﻿package javase.io;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class CustomerCareExecutive extends JFrame implements ActionListener, ItemListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JPanel panelObject;
	JLabel l1, l2, l3, l4, l5, l6, l7, l8;
	JTextField tf1;
	JRadioButton c1, c2;
	
	JComboBox cb1;
	JList li1;
	GridBagLayout gl;
	GridBagConstraints gbc;

	String criteria[] = { "Customer Satisfaction", "Productivity" };
	String rating[] = { "Outstanding", "Excellent", "Good", "Poor" };
	JButton b1;

	String grade = new String();

	public CustomerCareExecutive() {
		super("Customer Care Executive Window");
		gl = new GridBagLayout();
		gbc = new GridBagConstraints();
		panelObject = (JPanel) getContentPane();
		panelObject.setLayout(gl);

		l1 = new JLabel("Customer Care Executive Performance Sheet");
		l8 = new JLabel(
				"-----------------------------------------------------------------");
		l2 = new JLabel("Name :");
		l3 = new JLabel("Grade :");
		l4 = new JLabel("Performance Criteria");
		l5 = new JLabel("Rating");
		l6 = new JLabel("------------------------------");
		l7 = new JLabel("-----------");

		tf1 = new JTextField(10);
		tf1.setText("Carol");

		c1 = new JRadioButton("L1");
		c2 = new JRadioButton("L2");
		c1.addActionListener(this);
		c2.addActionListener(this);

		cb1 = new JComboBox(criteria);

		li1 = new JList(rating);

		b1 = new JButton("Submit");
		b1.addActionListener(this);

		gbc.anchor = GridBagConstraints.NORTHWEST;
		gbc.gridx = 3;
		gbc.gridy = 1;
		gl.setConstraints(l1, gbc);
		panelObject.add(l1);

		gbc.gridx = 3;
		gbc.gridy = 3;
		gl.setConstraints(l8, gbc);
		panelObject.add(l8);

		gbc.gridx = 2;
		gbc.gridy = 9;
		gl.setConstraints(l2, gbc);
		panelObject.add(l2);

		gbc.gridx = 4;
		gbc.gridy = 9;
		gl.setConstraints(tf1, gbc);
		panelObject.add(tf1);

		gbc.gridx = 2;
		gbc.gridy = 14;
		gl.setConstraints(l3, gbc);
		panelObject.add(l3);

		gbc.gridx = 4;
		gbc.gridy = 14;
		gl.setConstraints(c1, gbc);
		panelObject.add(c1);
		c1.addItemListener(this);

		gbc.gridx = 5;
		gbc.gridy = 14;
		gl.setConstraints(c2, gbc);
		panelObject.add(c2);
		c2.addItemListener(this);

		gbc.gridx = 2;
		gbc.gridy = 19;
		gl.setConstraints(l4, gbc);
		panelObject.add(l4);

		gbc.gridx = 4;
		gbc.gridy = 19;
		gl.setConstraints(l5, gbc);
		panelObject.add(l5);

		gbc.gridx = 2;
		gbc.gridy = 22;
		gl.setConstraints(l6, gbc);
		panelObject.add(l6);

		gbc.gridx = 4;
		gbc.gridy = 22;
		gl.setConstraints(l7, gbc);
		panelObject.add(l7);

		gbc.gridx = 2;
		gbc.gridy = 26;
		gl.setConstraints(cb1, gbc);
		panelObject.add(cb1);

		gbc.gridx = 4;
		gbc.gridy = 26;
		gl.setConstraints(li1, gbc);
		panelObject.add(li1);
		gbc.gridx = 5;
		gbc.gridy = 30;
		gl.setConstraints(b1, gbc);
		panelObject.add(b1);
		pack();
		setVisible(true);
	}

	public static void main(String args[]) {
		new CustomerCareExecutive();
	}

	public void actionPerformed(ActionEvent evt) {
		Object obj = evt.getSource();
		if (obj == b1) {
			String name = tf1.getText();
			int selection;
			String perfcriteria = String.valueOf(cb1.getSelectedItem());
			selection = li1.getSelectedIndex();

			String execrating = String.valueOf(li1.getSelectedValue());
			String record = "\n" + name + " : " + grade + " : " + perfcriteria
					+ " : " + execrating + " ; ";

			try {
				RandomAccessFile logFile = new RandomAccessFile(
						"Executive.txt", "rw");
				logFile.seek(logFile.length());
				logFile.writeBytes(record);
			} catch (IOException ev) {
				System.out.println("Cannot write to log file" + ev);
			}
		}

	}

	public void itemStateChanged(ItemEvent ev) {
		Object obj = ev.getSource();
		if (obj == c1)
			grade = "L1";
		if (obj == c2)
			grade = "L2";
	}
}
